/**
*
*@since
2022/10/12
22:30
*@author 鍚存倍
*/
package com.windgo.controller.admin;

import com.windgo.bean.bo.BrandCreateBo;
import com.windgo.bean.MarketBrand;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.service.BrandService;
import com.windgo.util.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    @RequestMapping("list")
    @RequiresPermissions("perms[admin:brand:list]")
    public BaseRespVo list(BasePageInfo basePageInfo,String name,Integer id){
        CommonData<MarketBrand> data= brandService.list(basePageInfo, name, id);
        return BaseRespVo.ok(data);
    }

    @PostMapping("delete")
    @RequiresPermissions("perms[admin:brand:delete]")
    public BaseRespVo delete(@RequestBody MarketBrand marketBrand){
        Integer id = marketBrand.getId();
        int i = brandService.delete(id);
        if(i!=1){
            return null;
        }
        return BaseRespVo.ok();
    }
    @PostMapping("create")
    @RequiresPermissions("perms[admin:brand:create]")
    public BaseRespVo create(@RequestBody MarketBrand marketBrand){
        if(marketBrand.getDesc()==null||marketBrand.getName()==null&&marketBrand.getFloorPrice()==null){
            return BaseRespVo.error();
        }
        MarketBrand data = brandService.insert(marketBrand);
        return BaseRespVo.ok(data);
    }
    @PostMapping("update")
    @RequiresPermissions("perms[admin:brand:update]")
    public BaseRespVo update(@RequestBody MarketBrand marketBrand){
        if(StringUtils.isEmpty(marketBrand.getDesc())||StringUtils.isEmpty(marketBrand.getName())){
            return BaseRespVo.error();
        }
        MarketBrand data = brandService.update(marketBrand);
        return BaseRespVo.ok(data);
    }
}
